import {
  RouteRecordRaw,
  createRouter,
  createWebHashHistory
} from 'vue-router'
import {
  App
} from 'vue'
import viewRouters from '@/views/router'
const routerHistory = createWebHashHistory()
// createWebHashHistory hash 路由
// createWebHistory history 路由
// createMemoryHistory 带缓存 history 路由
const Layout = () => import('@/layout')
export const constantRoute: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'Login',
    component: () => null
  }
]

const basicRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/views/home'),
    redirect: '/home',
    name: 'Home',
    meta: {
      title: '首页',
      icon: 'el-icon-s-home'
    },
    children: [
      {
        path: '/home',
        component: () => import('@/views/home'),
        name: 'Home',
        meta: {
          title: '首页',
          icon: 'el-icon-s-home'
        }
      }
    ]
  },
  {
    path: '/:catchAll(.*)',
    component: () => import('@/views/home/404'),
    name: '404'
  }
  // ...constantRoute
]

const router = createRouter({
  history: routerHistory,
  routes: basicRoutes
})

export function setupRouter(app: App<Element>): void {
  app.use(router)
}

export default router